<script>
import { getTabList, getCodeCategoryList } from '@/api/chat'
import List from '../List'
export default {
  components: { List },
  props: {},
  data() {
    return {
      groupIndex: 0,
      keyword: '',
      list: [],
      loading: false,
      finished: false,
      show: false,
      groupList: [], // 分组列表
      query: {},
      type: '4', //分组类型
      // userId: this.$store.state.userId,
    }
  },
  watch: {
    userId() {
      // this.getList()
    },
  },
  computed: {
    userId() {
      return this.$store.state.userId
    },
  },
  beforeCreate() {},
  created() {
    // this.$toast('userId:' + this.$store.state.userId)
    // this.userId && this.getList()
    // this.getList()
    this.getCodeCategoryListFn() // 获取分组列表
  },
  mounted() {},
  methods: {
    search(pageNum) {
      // this.$refs['list'][this.active].search(pageNum, this.keyword)
      if (this.query.categoryId) {
        this.$refs['list'] && this.$refs['list'].search(pageNum, this.keyword, this.query.categoryId)
      } else {
        this.$refs['list'] && this.$refs['list'].search(pageNum, this.keyword)
      }
    },
    cancel() {
      this.keyword = ''
      delete this.query.categoryId
      this.groupIndex = 0
      this.$nextTick(() => this.search(1))
    },
    refreshCollect() {
      // this.userId && this.$refs['list'][0].getList(1)
    },
    switchGroup(index, data) {
      this.groupIndex = index
      if (index !== 0) {
        this.query.categoryId = data.id
      } else {
        delete this.query.categoryId
      }
      this.search(1)
    },
    getCodeCategoryListFn() {
      getCodeCategoryList({ mediaType: '14' }).then((res) => {
        if (res.code == 200) {
          this.groupList = res.data
          this.groupList.unshift({
            name: '全部',
          })
          this.groupIndex = 0
          this.query.pageNum = 1
        }
      })
    },
    // add() {},
  },
}
</script>

<template>
  <div>
    <van-search v-model="keyword" show-action placeholder="请输入搜索关键词" @search="search(1)">
      <template #action>
        <span @click="search(1)">搜索</span>
        <span class="ml5" @click="cancel">重置</span>
      </template>
    </van-search>
    <!-- <div style="display:flex;justify-content:space-between;width:100%"> -->
    <div
      style="display:flex;justify-content:space-between;align-items: stretch; width: 100%; height: calc(100vh - 64px);"
    >
      <div class="item-list">
        <div
          class="item"
          :class="{ active: groupIndex == key }"
          v-for="(group, key) in groupList"
          :key="group.id"
          @click="switchGroup(key, group)"
        >
          <div class="name">{{ group.name }}</div>
        </div>
      </div>
      <div style="width: 70%;overflow:auto">
        <List ref="list" :talkType="1"></List>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
.van-tab__pane {
  display: flex;
}
.page {
  height: 100vh;
  background: #f6f6f6;
}
/deep/ .list {
  padding: 10px;
  background: #fff;
  border-top: 1px solid #eee;
  .info {
    padding-top: 10px;
  }
  .action {
    padding-left: 5px;
  }
}
.item-list {
  margin-top: 10px;
  width: 30%;
  background-color: #fff;
  height: 100%;
  padding-top: 15px;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  .item {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    color: rgba(0, 0, 0, 0.6);
    height: 40px;
    line-height: 40px;
    width: 100%;
    padding-left: 20px;
    .name {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    .dropdown {
      // display: none;
      .dot {
        cursor: pointer;
        width: 15px;
        height: 15px;
        line-height: 15px;
        font-size: 14px;
        font-family: JMT-Font, JMT;
        font-weight: normal;
        color: rgba(0, 0, 0, 0.6);
        margin-right: 10px;
        margin-left: 5px;
        font-weight: 500;
        .content-icon {
          color: rgba(0, 0, 0, 0.6);
          font-size: 12px;
          transform: rotate(90deg);
        }
      }
    }
    &:hover {
      color: rgba(0, 0, 0, 0.9);
      background: #f5f8fe;
      opacity: 0.8;
      border-radius: 2px;
      .dropdown {
        // display: block;
      }
    }
  }

  .active {
    // border-left: 2px solid #3c88f0;
    color: rgba(0, 0, 0, 0.9);
    background: #f5f8fe;
    border-radius: 2px;
  }
}
</style>
